﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using University.Workshop.Presentation.Kardex.Register;
using University.Workshop.Presenters.Kardex.Search;

namespace University.Workshop.Presentation.Kardex
{
    /// <summary>
    /// Interaction logic for SearchKardex.xaml
    /// </summary>
    public partial class SearchKardex : Page,ISearchKardexView
    {
        PresenterSeachKardex pSearchKardex;
        public SearchKardex()
        {
            InitializeComponent();
            pSearchKardex = new PresenterSeachKardex(this);
        }

        private void NewKardexBtn_Click(object sender, RoutedEventArgs e)
        {
            this.NavigationService.Navigate(new PageRegisterView());
        }

        private void SearchBtn_Click(object sender, RoutedEventArgs e)
        {
            pSearchKardex.SearchKardex();
        }

        public ICollection<Model.Kardex> KardexFinded
        {
            get
            {
                if (KardexFindeddtgv.ItemsSource == null)
                    new List<Model.Kardex>();
                return (ICollection<Model.Kardex>) KardexFindeddtgv.ItemsSource;
            }
            set
            {
                KardexFindeddtgv.ItemsSource = null;
                KardexFindeddtgv.ItemsSource = value;
            }
        }


        public void NotifyErrorMessage(string MessageValue)
        {
            MessageBox.Show(App.Current.MainWindow, MessageValue, "Error!!!", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.RightAlign);
        }
        public void NotifySystemMessage(string MessageValue)
        {
            MessageBox.Show(App.Current.MainWindow, MessageValue, "Atencion!!!", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK, MessageBoxOptions.RightAlign);
        }

        private void ShowKardex_Click(object sender, RoutedEventArgs e)
        {

            this.NavigationService.Navigate(new Presentation.Kardex.Show.PageShowView((Model.Kardex)KardexFindeddtgv.SelectedItem));
        }

        private void ModifyKardex_Click(object sender, RoutedEventArgs e)
        {
            pSearchKardex.ModifyKardex();
        }


        public string StateKardex
        {
            get {
                return KardexStatedd.SelectionBoxItem.ToString();
            }
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            App.Current.MainWindow.Title = "UIBuscarKardex";
        }


        public string PersonIdRelative
        {
            get
            {
                return PersonIdRelativeTxBx.Text;
            }
            set { PersonIdRelativeTxBx.Text = value; }
        }

        public string PersonLastNamesRelative
        {
            get
            {
                return PersonLastNamesTxbx.Text;
            }
            set { PersonLastNamesTxbx.Text = value; }
        }

        public string PersonNamesRelative
        {
            get
            {
                return PersonNameRelativeTxbx.Text;
            }
            set
            {
                PersonNameRelativeTxbx.Text=value;
            }
        }

        private void DisableKardex_Click(object sender, RoutedEventArgs e)
        {
            pSearchKardex.ShowDisableKardex();
        }

        private void EnableKardex_Click(object sender, RoutedEventArgs e)
        {
            pSearchKardex.EnableKardex();
        }


        public bool NotifyConfirmationMessage(string MessageValue)
        {
            return MessageBox.Show(App.Current.MainWindow, 
                MessageValue, 
                "Atencion!!!", 
                MessageBoxButton.YesNo, 
                MessageBoxImage.Information, 
                MessageBoxResult.Yes, 
                MessageBoxOptions.RightAlign) == MessageBoxResult.Yes;
        }

        public void OpenDisableKardexPopUp(Model.Kardex k)
        {
            if (k != null)
            {
                Back1.Visibility = Visibility.Visible;
                BackDisable.Visibility = Visibility.Visible;
                PersonCiTxt.Content = k.Person.PersonId;
                PersonNamesForDisableTxt.Content = k.Person.Names;
                PersonLastNamesForDisableTxt.Content = k.Person.LastNames;
                PersonSquareForDisabelLbl.Content = k.AllotmentModel.SquareId;
                PersonAllotmentForDisableLbl.Content = k.AllotmentModel.AllotmentName;
                App.Current.MainWindow.Title = "UIInhabilitarKardex";
            }
        }


        public Model.Kardex KardexSelected
        {
            get { return (Model.Kardex)KardexFindeddtgv.SelectedItem; }
        }

        public void HideDisableKardex()
        {
            Back1.Visibility = Visibility.Hidden;
            BackDisable.Visibility = Visibility.Hidden;
            PersonCiTxt.Content = string.Empty;
            PersonNamesForDisableTxt.Content = string.Empty;
            PersonLastNamesForDisableTxt.Content = string.Empty;
            PersonSquareForDisabelLbl.Content = string.Empty;
            PersonAllotmentForDisableLbl.Content = string.Empty;
            App.Current.MainWindow.Title = "UIBuscarKardex";
        }
        public void GoToModifyKardex(Model.Kardex kardex)
        {
            this.NavigationService.Navigate(new Presentation.Kardex.Modify.PageModifyView(kardex));
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            pSearchKardex.DisableKardex();
        }


        private void button1_Click(object sender, RoutedEventArgs e)
        {
            pSearchKardex.HideDisableKardex();
        }

        private void ReportKardex_Click(object sender, RoutedEventArgs e)
        {
            pSearchKardex.CreateReport();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {

            pSearchKardex.ShowReport();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {

            pSearchKardex.HideReportKardex();
        }




        public void HideReportKardex()
        {
            Back1.Visibility = Visibility.Hidden;
            BackReport.Visibility = Visibility.Hidden;
            periodCalendar.SelectedDate = System.DateTime.Now;
            periodCalendar.DisplayDate = System.DateTime.Now;
            App.Current.MainWindow.Title = "UIBuscarKardex";
        }

        public int YearReportSelected
        {
            get { return periodCalendar.SelectedDate.Value.Year; }
            set { periodCalendar.SelectedDate=new DateTime(value,1,1); }
        }

        public void ShowReportKardex()
        {
                Back1.Visibility = Visibility.Visible;
                BackReport.Visibility = Visibility.Visible;
                periodCalendar.SelectedDate = System.DateTime.Now;
                periodCalendar.DisplayDate = System.DateTime.Now;
            App.Current.MainWindow.Title = "UIReporteKardex";
        }

        private void periodCalendar_DisplayModeChanged(object sender, CalendarModeChangedEventArgs e)
        {
            if (e.NewMode != CalendarMode.Decade)
            {
                DateTime dt = ((Calendar) sender).DisplayDate;
                ((Calendar)sender).DisplayMode = CalendarMode.Decade;
                ((Calendar)sender).DisplayDate = dt;
                ((Calendar)sender).SelectedDate = dt;
            }
        }

        private void periodCalendar_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;
        }
    }
}